(sortBlock value: di value: dj) "i.e., should di precede dj?"
ifFalse:
[self swap: i with: j.
tt _ di.
di _ dj.
dj _ tt].
n > 2
ifTrue: "More than two elements."
[ij _ (i + j) // 2. "ij is the midpoint of i and j."
dij _ self basicAt: ij. "Sort di,dij,dj. Make dij be their median."
(sortBlock value: di value: dij) "i.e. should di precede dij?"
ifTrue:
[(sortBlock value: dij value: dj) "i.e., should dij precede dj?"
ifFalse:
[self swap: j with: ij.
dij _ dj]]
ifFalse: "i.e. di should come after dij"
[self swap: i with: ij.
dij _ di].
n > 3
ifTrue: "More than three elements."
["Find k>i and l<j such that dk,dij,dl are in reverse order.
Swap k and l. Repeat this procedure until k and l pass each other."
k _ i.
l _ j.
[[l _ l - 1. k <= l and: [sortBlock value: dij value: (self basicAt: l)]]
whileTrue. "i.e. while dl succeeds dij"
[k _ k + 1. k <= l and: [sortBlock value: (self basicAt: k) value: dij]]
whileTrue. "i.e. while dij succeeds dk"
k <= l]
whileTrue:
[self swap: k with: l].
"Now l<k (either 1 or 2 less), and di through dl are all less than or equal to dk
through dj. Sort those two segments in parallel."
[self parallelSort: i to: l] inParallelWith: [self parallelSort: k to: j]]]! !'From Smalltalk-80, version 2, of April 1, 1983 on 29 March 1987 at 5:07:32 pm'!
!Collection methodsFor: 'converting'!
asParallelSortedCollection
"Answer a new instance of SortedCollection whose elements are the elements of
the receiver. The sort order is the default less than or equal ordering.